import { Http, Headers, Response,Jsonp, RequestOptions, URLSearchParams } from '@angular/http';
import 'rxjs/add/operator/toPromise';

import { Injectable } from '@angular/core';

import { Position } from './position';
import { SERVER } from '../../app.config';

@Injectable()
export class PositionService {
    constructor(private http: Http){

    }

    getPosition(): Promise<Position[]> {
        return this.http.get(SERVER.TRACK.BUS)
        .toPromise()
        .then(this.extractData)
        .catch(this.handleError);
    }
    private handleError(error: any): Promise<any> {
        console.error('错误：', error);

        return Promise.reject(error.message || error);
    }

    private extractData(res: Response) {
        let data = res.json();
        return data || { };
    }
}